﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>添加编辑菜单</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
</head>
<body>
  <div class="layui-form layui-form-pane" lay-filter="form-add" id="form-add" style="padding: 20px 30px 0 20px;">
    <input type="hidden" name="id" value="" />
    <input type="hidden" name="parentid" value="" />
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">父级菜单</label>
      <div class="layui-input-inline">
        <input type="text" name="parentname" disabled style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">菜单名称</label>
      <div class="layui-input-inline">
        <input type="text" name="name" lay-verify="required" style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">菜单标识</label>
      <div class="layui-input-inline">
        <input type="text" name="markup" style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">菜单图标</label>
      <div class="layui-input-inline">
        <input type="text" name="icon" style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">菜单地址</label>
      <div class="layui-input-inline">
        <input type="text" name="url" style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label" style="width: 100px">菜单排序</label>
      <div class="layui-input-inline">
        <input type="text" name="display" style="width:300px;" value="" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="btn_submit" id="btn_submit" value="确定">
    </div>
 </div>
<script src="/plugins/layui/layui.js"></script> 
  <script>
  layui.config({
    base: '/plugins/layuiadmin/'
  }).extend({
    index: 'lib/index'
  }).use(['index', 'form'], function(){
    var $ = layui.$, form = layui.form, router = layui.router();
    layer.load(2);
    $.ajax({
        type: "get",
        url: "menu_add",
        data: router.search,
        dataType: "json",
        success: function (res) {
            layer.closeAll('loading'); 
            if (res.code == 0) {
                form.val("form-add", res.data);
            }
            else {
                layer.alert(data.msg);
            }
        }
    });
    //监听提交
    form.on('submit(btn_submit)', function (data) {
        layer.load(2);
        var field = data.field; //获取提交的字段
        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
        $(this).addClass("layui-btn-disabled").prop("disabled" , true);
        //提交 Ajax 成功后，关闭当前弹层并重载表格
        $.ajax({
            type: "post",
            url: "menu_add",
            data: field,
            dataType: "json",
            success: function (data) {
                layer.closeAll('loading'); 
                if (data.code == 0)
                {
                    layer.msg(data.msg,{time:1*1000},function(){
                        parent.layui.treeGrid.reload('treeTable'); //重载表格
                        parent.layer.close(index); //再执行关闭 
                    });
                }
                else
                {
                    layer.alert(data.msg)
                }
            }
        });
    });
  })
  </script>
</body>
</html>